package com.peanut.baby.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.RadioButton;

import com.peanut.baby.R;


public class TitleTabRadioButton extends RadioButton {

	int lineWidth,lineHeight;
	Paint selectedPaint;

	public TitleTabRadioButton(Context context, AttributeSet attrs,
                               int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}

	public TitleTabRadioButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TitleTabRadioButton(Context context) {
		super(context);
		init();
	}
	
	private void init(){
		lineWidth = dip2px(getContext(),20);
		lineHeight = dip2px(getContext(),3);

	}

	private Paint getSelectedPaint(){
		if(selectedPaint == null){
			selectedPaint = new Paint();
			selectedPaint.setAntiAlias(true);
			selectedPaint.setColor(getContext().getResources().getColor(R.color.colorPrimary));
			selectedPaint.setStyle(Style.FILL);
		}
		return selectedPaint;
	}
	
	@Override
	public void setChecked(boolean checked) {
		// TODO Auto-generated method stub
		super.setChecked(checked);
	}

	
	 public int dip2px(Context context, float dpValue) {
	        final float scale = context.getResources().getDisplayMetrics().density;
	        return (int) (dpValue * scale + 0.5f);
	    }

	@Override
	public void draw(Canvas canvas) {
		super.draw(canvas);
		
		if(isChecked()){
			//画个小红点
			canvas.drawRect(getWidth() / 2 - lineWidth / 2,getHeight() - lineHeight, getWidth() / 2 + lineWidth / 2, getHeight(),getSelectedPaint());
		}
	}
	

}
